package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/08 09:51
 **/
public class Day6_2_Num121_MaxProfit {
    class Solution {
        public int maxProfit(int[] prices) {
            if(prices.length <= 1) return 0;
            int min = prices[0], maxVal = 0;
            for(int i = 1; i < prices.length; ++i){
                if(min < prices[i]) maxVal = Math.max(maxVal, prices[i] - min);
                else min = prices[i];
            }
            return maxVal;
        }
    }
}